from wordcloud import WordCloud
import matplotlib.pyplot as plt
# from matplotlib import rcParams
#
# config = {
#     "font.family": 'Times New Roman',  # 设置字体类型
#     "axes.unicode_minus": False  # 解决负号无法显示的问题
# }
# rcParams.update(config)
# 关键词列表
words = [
    "漏损控制", "水务管理", "DMA分区", "管网监测", "水资源节约", "漏点分析",
    "夜间最小流量", "水平衡分析", "压力模型", "告警系统", "工单管理",
    "检漏稽查", "GIS系统", "数据分析", "产销差", "节水型社会", "供水效率",
    "漏损管控平台", "智能水务", "管网维护"
]

# 将关键词转换为字符串
text = ' '.join(words)

# 创建词云对象，指定字体路径
wordcloud = WordCloud(width=800, height=400, background_color='white', font_path='msyh.ttc').generate(text)

# 显示词云图片
plt.figure(figsize=(10, 5))
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis('off')
plt.show()

# 保存词云图片
wordcloud.to_file('wordcloud.png')